package com.ims.core.doc.service.impl;

import java.util.List;
import com.ims.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ims.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ims.core.doc.domain.TInNon1003Entry;
import com.ims.core.doc.mapper.TInNon1003Mapper;
import com.ims.core.doc.domain.TInNon1003;
import com.ims.core.doc.service.ITInNon1003Service;

/**
 * 航空电子客票行程单Service业务层处理
 *
 * @author IMS
 * @date 2024-11-20
 */
@Service
public class TInNon1003ServiceImpl implements ITInNon1003Service
{
    @Autowired
    private TInNon1003Mapper tInNon1003Mapper;

    /**
     * 查询航空电子客票行程单
     *
     * @param id 航空电子客票行程单主键
     * @return 航空电子客票行程单
     */
    @Override
    public TInNon1003 selectTInNon1003ById(Long id)
    {
        return tInNon1003Mapper.selectTInNon1003ById(id);
    }

    /**
     * 查询航空电子客票行程单列表
     *
     * @param tInNon1003 航空电子客票行程单
     * @return 航空电子客票行程单
     */
    @Override
    public List<TInNon1003> selectTInNon1003List(TInNon1003 tInNon1003)
    {
        return tInNon1003Mapper.selectTInNon1003List(tInNon1003);
    }

    /**
     * 新增航空电子客票行程单
     *
     * @param tInNon1003 航空电子客票行程单
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertTInNon1003(TInNon1003 tInNon1003)
    {
        tInNon1003.setCreateTime(DateUtils.getNowDate());
        int rows = tInNon1003Mapper.insertTInNon1003(tInNon1003);
        insertTInNon1003Entry(tInNon1003);
        return rows;
    }

    /**
     * 修改航空电子客票行程单
     *
     * @param tInNon1003 航空电子客票行程单
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateTInNon1003(TInNon1003 tInNon1003)
    {
        tInNon1003.setUpdateTime(DateUtils.getNowDate());
        tInNon1003Mapper.deleteTInNon1003EntryByInvoiceId(tInNon1003.getId());
        insertTInNon1003Entry(tInNon1003);
        return tInNon1003Mapper.updateTInNon1003(tInNon1003);
    }

    /**
     * 批量删除航空电子客票行程单
     *
     * @param ids 需要删除的航空电子客票行程单主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteTInNon1003ByIds(Long[] ids)
    {
        tInNon1003Mapper.deleteTInNon1003EntryByInvoiceIds(ids);
        return tInNon1003Mapper.deleteTInNon1003ByIds(ids);
    }

    /**
     * 删除航空电子客票行程单信息
     *
     * @param id 航空电子客票行程单主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteTInNon1003ById(Long id)
    {
        tInNon1003Mapper.deleteTInNon1003EntryByInvoiceId(id);
        return tInNon1003Mapper.deleteTInNon1003ById(id);
    }

    /**
     * 新增航空电子客票行程单明细信息
     *
     * @param tInNon1003 航空电子客票行程单对象
     */
    public void insertTInNon1003Entry(TInNon1003 tInNon1003)
    {
        List<TInNon1003Entry> tInNon1003EntryList = tInNon1003.getTInNon1003EntryList();
        String invoiceId = tInNon1003.getInvoiceId();
        if (StringUtils.isNotNull(tInNon1003EntryList))
        {
            List<TInNon1003Entry> list = new ArrayList<TInNon1003Entry>();
            for (TInNon1003Entry tInNon1003Entry : tInNon1003EntryList)
            {
                tInNon1003Entry.setInvoiceId(invoiceId);
                list.add(tInNon1003Entry);
            }
            if (list.size() > 0)
            {
                tInNon1003Mapper.batchTInNon1003Entry(list);
            }
        }
    }
}
